package br.ufrj.dcc.tp.main;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ThreadMain extends Thread {
	
	private Method method;
	private String[] args;
	
	@SuppressWarnings("unchecked")
	public ThreadMain(String className, String[] args) throws Exception {
		Class klass = Class.forName(className);
		method = klass.getMethod("main", String[].class);
		
		if( ! Modifier.isStatic(method.getModifiers()) ) {
			throw new Exception("Classe nao valida.");
		}
		
		this.args = args;
	}
	
	@Override
	public void run() {
		try {
			method.invoke(null, (Object)args);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}
}
